package com.thwj.project.biz.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.thwj.common.annotation.Log;
import com.thwj.common.core.controller.BaseController;
import com.thwj.common.core.domain.AjaxResult;
import com.thwj.common.core.page.TableDataInfo;
import com.thwj.common.enums.BusinessType;
import com.thwj.common.utils.poi.ExcelUtil;
import com.thwj.project.biz.domain.UserAccountInout;
import com.thwj.project.biz.service.IUserAccountInoutService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.Arrays;
import java.util.List;

/**
 * 用户出入账明细Controller
 *
 * @author generate
 * @date 2023-06-16
 */
@RestController
@RequestMapping("/biz/inout")
public class UserAccountInoutController extends BaseController {
    @Autowired
    private IUserAccountInoutService userAccountInoutService;

/**
 * 查询用户出入账明细列表
 */
@PreAuthorize("@ss.hasPermi('biz:inout:list')")
@GetMapping("/list")
    public TableDataInfo list(UserAccountInout userAccountInout) {
        //startPage();
        List<UserAccountInout> list = userAccountInoutService.list(new QueryWrapper<>(userAccountInout).orderByDesc("create_date"));
        return getDataTable(list);
    }

    /**
     * 导出用户出入账明细列表
     */
    @PreAuthorize("@ss.hasPermi('biz:inout:export')")
    @Log(title = "用户出入账明细", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, UserAccountInout userAccountInout) {
        List<UserAccountInout> list = userAccountInoutService.list(new QueryWrapper<>(userAccountInout));
        ExcelUtil<UserAccountInout> util = new ExcelUtil<UserAccountInout>(UserAccountInout. class);
        util.exportExcel(response, list, "用户出入账明细数据");
    }

    /**
     * 获取用户出入账明细详细信息
     */
    @PreAuthorize("@ss.hasPermi('biz:inout:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(userAccountInoutService.getById(id));
    }

    /**
     * 新增用户出入账明细
     */
    @PreAuthorize("@ss.hasPermi('biz:inout:add')")
    @Log(title = "用户出入账明细", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody UserAccountInout userAccountInout) {
        return toAjax(userAccountInoutService.save(userAccountInout));
    }

    /**
     * 修改用户出入账明细
     */
    @PreAuthorize("@ss.hasPermi('biz:inout:edit')")
    @Log(title = "用户出入账明细", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody UserAccountInout userAccountInout) {
        return toAjax(userAccountInoutService.updateById(userAccountInout));
    }

    /**
     * 删除用户出入账明细
     */
    @PreAuthorize("@ss.hasPermi('biz:inout:remove')")
    @Log(title = "用户出入账明细", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(userAccountInoutService.removeByIds(Arrays.asList(ids)));
    }
}
